# -*- coding:utf-8 -*-

import os

class DB_MySQL():
    def __init__(self,host,username,passwd,dbname,tablename):
        try:
            from PyDB_MySql import MySql
        except Exception as e:
            print e
        finally:
            self.mysql = MySql(host,username,passwd,dbname,tablename)

    #将数据以列表形式返回     -- 每一行一条用例
    def get_OneTestCase_row_RList(self):
        return self.mysql.get_OneTestCase_row_RList()

    # 根据用例编号以列表形式返回测试用例
    def get_OneTestCase_by_testNO(self, testNO):
        return self.mysql.get_OneTestCase_row_RList(testNO)

    #将数据以字典形式返回     -- 每一行一条用例
    def get_OneTestCase_row_RDist(self):
        return self.mysql.get_OneTestCase_row_RDist()

    # 将数据以列表形式返回    -- 每一列一条用例
    def get_oneTestCase_column_RList(self):
        return self.mysql.get_OneTestCase_column_RList()

    # 将数据以字典形式返回    -- 每一列一条用例
    def get_oneTestCase_column_RDist(self):
        return self.mysql.get_OneTestCase_column_RDist()

    #FilePath单独进行读取
    def get_globe_dict(self):
        return self.mysql.Globe_dict()


class DB_Excel():
    def __init__(self,excelpath,sheetname):
        try:
            from PyDB_Excel import Excel
        except Exception as e:
            print e
        finally:
            self.excel = Excel(excelpath, sheetname)

    # 将数据以列表形式返回    -- 每一行一条用例
    def get_OneTestCase_row_RList(self):
        return self.excel.get_OneTestCase_row_RList()

    # 根据用例编号以列表形式返回测试用例
    def get_OneTestCase_by_testNO(self,testNO):
        return self.excel.get_OneTestCase_row_RList(testNO)

    # 将数据以字典形式返回    -- 每一行一条用例
    def get_OneTestCase_row_RDist(self):
        return self.excel.get_OneTestCase_row_RDist()

    # 将数据以列表形式返回    -- 每一列一条用例
    def get_OneTestCase_column_RList(self):
        return self.excel.get_OneTestCase_column_RList()

    # 将数据以字典形式返回    -- 每一列一条用例
    def get_OneTestCase_column_RDist(self):
        return self.excel.get_OneTestCase_column_RDist()

    # FilePath单独进行读取
    def get_globe_dict(self):
        return self.excel.Globe_dict()


if __name__ == '__main__':

    # dberl = DB_Excel(os.getcwd() + u'\\inputdata\\TestCase.xlsx',u'FilePath').get_OneTestCase_row_RList()
    # dberd = DB_Excel(os.getcwd() + u'\\inputdata\\TestCase.xlsx',u'PreProcessor').get_OneTestCase_row_RDist()
    # dbecd = DB_Excel(u'F:\\自动化项目\\AutoTestBHF\\TestCaseExcel\\BHFTestCase辽宁.xlsx',u'执勤道路').get_OneTestCase_column_RDist()
    # ddict = DB_Excel(os.getcwd() + u'\\inputdata\\TestCase.xlsx',u'FilePath').get_globe_dict()
    # print dberl, '\n', dberd, '\n', dbecd,'\n', ddict
    # for j in dberd:
    #     print 80 * '='
    #     for k, l in j.items():
    #         print k, ': ', l
    #
    # for t in dbecd:
    #     print 80 * '='
    #     for x, y in t.items():
    #         print x, ': ', y
    #
    # for a,b in ddict.items():
    #     print 80 * '='
    #     print a,":",b

    aa  = DB_Excel(os.getcwd() + u'\\inputdata\\TestCase.xlsx',u'PreProcessor').get_OneTestCase_by_testNO("TP2")
    print aa



    # dbml = DB_MySQL('192.168.1.203', 'autotest', 'autotest', 'autotest', 'SGZH').get_OneTestCase_RList()
    # dbmd = DB_MySQL('192.168.1.203', 'autotest', 'autotest', 'autotest', 'SGZH').get_OneTestCase_RDist()
    # dbdict = DB_MySQL('192.168.1.203', 'autotest', 'autotest', 'autotest', 'FilePath').get_globe_dict()
    # print dbml, '\n', dbmd,'\n',dbdict
    # for i in dbmd:
    #     print 80 * '='
    #     for m, n in i.items():
    #         print m, ': ', n
    #
    # for o,p in dbdict.items():
    #     print 80 * '=',"\n",o,":",p

    bb = DB_MySQL('192.168.1.203', 'autotest', 'autotest', 'autotest', 'PreProcessor').get_OneTestCase_by_testNO("TP5")
    print bb
